package com.dalei.vdsmanager.management.vds.action;

import com.dalei.vdsmanager.management.vds.service.VDSUserService;
import com.opensymphony.xwork2.ActionSupport;

public class ChangeVDSUserPasswordAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6658578401779993415L;

	private VDSUserService vdsUserService;

	private int id;

	private String password;

	private String repeatPassword;

	public VDSUserService getVdsUserService() {
		return vdsUserService;
	}

	public void setVdsUserService(VDSUserService vdsUserService) {
		this.vdsUserService = vdsUserService;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRepeatPassword() {
		return repeatPassword;
	}

	public void setRepeatPassword(String repeatPassword) {
		this.repeatPassword = repeatPassword;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		// return super.execute();
		boolean result = vdsUserService.changePassword(id, password);
		if (result) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	@Override
	public void validate() {
		// TODO Auto-generated method stub
		super.validate();
		clearFieldErrors();
		if (password == null) {
			addFieldError("password",
					getText("changeVDSUserPassword.password.null"));
		} else {
			if (repeatPassword == null) {
				addFieldError("repeatPassword",
						getText("changeVDSUserPassword.repeatPassword.null"));
			} else {
				if (!repeatPassword.equals(password)) {
					addFieldError(
							"repeatPassword",
							getText("changeVDSUserPassword.repeatPassword.notMatch"));
				}
			}
		}
	}
}
